import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import Home from '@/views/Home.vue'
import UserManagement from '@/views/UserManagement.vue'
import MeetingManagement from '@/views/MeetingManagement.vue'
import MaterialManagement from '@/views/MaterialManagement.vue'
import GuestManagement from '@/views/GuestManagement.vue'
import ActivityManagement from '@/views/ActivityManagement.vue'
import ExhibitorManagement from '@/views/ExhibitorManagement.vue'
import NewsManagement from '@/views/NewsManagement.vue'
import PhotoManagement from '@/views/PhotoManagement.vue'
import Meeting from '@/views/Meeting.vue'

// 定义路由
const routes: RouteRecordRaw[] = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/components/Login.vue'),
    meta: { requiresAuth: false }
  },
  {
    path: '/',
    component: () => import('@/components/MainLayout.vue'),
    redirect: '/login',
    children: [
      {
        path: '/home',
        name: 'Home',
        component: () => import('@/views/Home.vue'),
        meta: { requiresAuth: true, title: '首页' }
      },
      { path: 'users', name: 'UserManagement', component: UserManagement },
      { path: 'meetings', name: 'MeetingManagement', component: MeetingManagement },
      { path: 'materials', name: 'MaterialManagement', component: MaterialManagement },
      { path: 'guests', name: 'GuestManagement', component: GuestManagement },
      { path: 'activities', name: 'ActivityManagement', component: ActivityManagement },
      { path: 'exhibitors', name: 'ExhibitorManagement', component: ExhibitorManagement },
      { path: 'news', name: 'NewsManagement', component: NewsManagement },
      { path: 'photos', name: 'PhotoManagement', component: PhotoManagement },
      { path: 'meeting', name: 'Meeting', component: Meeting },
    ]
  },
]

// 创建路由实例
const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫（权限校验）
// router.beforeEach(async (to, from) => {
//   const isAuthenticated = localStorage.getItem('token')
//   if (!isAuthenticated && to.path !== '/login') return '/login'
// })

export default router
